﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GooNews.ViewModels;
using Microsoft.Phone.Controls;
using AgiliTrain.Phone.Utilities.EventArgs;

namespace GooNews.Controls
{
  /// <summary>
  /// The page of news as it's shown.
  /// </summary>
  public partial class NewsPageControl : UserControl
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="NewsPageControl"/> class.
    /// </summary>
    public NewsPageControl()
    {
      InitializeComponent();

      Loaded += new RoutedEventHandler(NewsPageControl_Loaded);
    }

    void NewsPageControl_Loaded(object sender, RoutedEventArgs e)
    {
      // Load the feed once the page has loaded
      var feed = DataContext as Feed;
      if (feed != null && !feed.IsBusy && !feed.IsLoaded) feed.LoadFeedAsync();
    }

    /// <summary>
    /// Handles the MessageSent event of the NewsItemControl control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="AgiliTrain.Phone.Utilities.EventArgs.MessageEventArgs"/> instance containing the event data.</param>
    private void NewsItemControl_MessageSent(object sender, MessageEventArgs e)
    {
      App.ThisApp.ShowMessage(e.Message);
    }
  }
}
